<!-- DNS服务器设置弹窗 | 作者：menghao.yan | 邮箱：yxs2615@163.com | 时间：2023年08月12日 23:36:17 -->
<template>
  <!-- 弹出框 -->
  <a-modal v-model:open="visible" title="DNS服务器设置" width="500px" class="y-modal" okText="创建" @ok="onSubmit" @cancel="onCancel">
    <a-row>
      <a-col :span="24">
        <a-alert banner message="说明: 修改网络参数会重启网络,可能造成数据传输中断或错误,修改时请确保服务停止或未使用!" type="warning" show-icon />
      </a-col>
    </a-row>
    <a-form :label-col="{ span: 6 }" :wrapper-col="{span: 14}">
      <a-form-item label="DNS服务器" v-bind="validateInfos.dnsServer1">
        <a-input v-model:value="modelRef.dnsServer1" placeholder="请输入DNS服务器" />
      </a-form-item>
      <a-form-item label="DNS服务器" v-bind="validateInfos.dnsServer2">
        <a-input v-model:value="modelRef.dnsServer2" placeholder="请输入DNS服务器" />
      </a-form-item>
      <a-form-item label="DNS服务器" v-bind="validateInfos.dnsServer3">
        <a-input v-model:value="modelRef.dnsServer3" placeholder="请输入DNS服务器" />
      </a-form-item>
    </a-form>
  </a-modal>
</template>

<script setup>
const props = defineProps({
  visible: {
    type: Boolean,
    default: false
  }
})

const { visible } = toRefs(props)

// 定义组件的事件
const emits = defineEmits(['update:visible'])

import { Form } from 'ant-design-vue'

const useForm = Form.useForm

const modelRef = reactive({
  dnsServer1: '',
  dnsServer2: '',
  dnsServer3: ''
})

const rulesRef = reactive({
  dnsServer1: [
    {
      required: true,
      message: '请选择DNS服务器'
    }
  ],
  dnsServer2: [
    {
      required: true,
      message: '请选择DNS服务器'
    }
  ],
  dnsServer3: [
    {
      required: true,
      message: '请选择DNS服务器'
    }
  ]
})

const { resetFields, validate, validateInfos, mergeValidateInfo } = useForm(modelRef, rulesRef)
const onSubmit = () => {
  validate()
    .then(() => {
      console.log('DNS服务器设置>>' , toRaw(modelRef))
      onCancel()
    })
    .catch(err => {
      console.log('error', err)
    })
}

const onCancel = () => {
  // 触发自定义事件来通知父组件关闭弹窗
  emits('update:visible', false)
}
</script>

<style scoped>
.ant-row {
  margin-bottom: 10px;
}
</style>